(function($) {
	$.extend($.fn.datagrid.defaults.view,{
		onAfterRender:function(jq){
		$(jq).datagrid("hideColumn");
		$(jq).datagrid("columnsWidth");
		//$(jq).datagrid("emptyData");
		return $(jq).each(function() {
			$(this).datagrid("_initRowOptButtons");
			setTimeout(function(){$('tr').unbind('click')},100);
		})
		
	}
	});
	
	$.extend($.fn.datagrid.methods,
			{
		    
		autoresize:function(jq,obj)
	    {		
		 $(jq[0]).datagrid("runresize",obj);
		 
		},
		
		 autoresizeForTreeGrid:function(jq,obj)
		{		
		 $(jq[0]).datagrid("runresizeForTreeGrid",obj);
		},
		 
		runresize:function(jq,obj)
		    {	
			/*
			*o:要适应变换的面板
			*w:所在窗口对象
			*rh:要去除的高度(元素下方距离容器边缘的高度)
			*/
			var container = $(jq[0]).parent().parent().parent();		
			var containerDiv = $(jq[0]).parent().parent().parent().parent();
	        var containertop= container.offset().top;
			var theight;

			if(obj != null && obj.rh != null){
				theight = getWinSize.winHeight()-containertop-3+3-obj.rh;
			}else{
				theight = getWinSize.winHeight()-containertop-3+3;
			}
	        
			if($(jq[0]).height != theight|| $(jq[0]).width !=twidth)
			   {      
				/*
				*249:左边west宽度
				*9:resizebar打开时宽度
				*6:resizebar关闭时宽度
				*20:当前表格所在区域两边padding
				*面板缩放或者窗口缩放
				*/
				//ie does not support css("padding")
				/*
				*17:DIV滚动条宽度
				*/
				//判断DiV是否出现滚动条
				var divScrollWidth = 0;
				//alert($(containerDiv)[0].scrollHeight+"**"+$(containerDiv)[0].clientHeight+"**"+$(containerDiv)[0].offsetHeight+"**"+$(containerDiv)[0].clientHeight);
				if($(containerDiv)[0].scrollHeight>$(containerDiv)[0].clientHeight||$(containerDiv)[0].offsetHeight>$(containerDiv)[0].clientHeight){
					divScrollWidth = 17;
				}
				if(obj != undefined){
					if(obj.innerGrid != undefined && obj.innerGrid != null){
						divScrollWidth = 17;
						theight = 200;
					}
				}
				twidth = getWinSize.winWidth()-3-container.offset().left-divScrollWidth; 
				
				/*设置datagrid遮罩层宽高*/
				$(".datagrid-mask").width(twidth);
				$(".datagrid-mask").height(theight);
				
				$(jq[0]).datagrid('resize', {
					width:twidth,
					height:theight
				});
		 
			   }
			$(jq[0]).datagrid("columnsWidth",jq);
			/*var emptyData = $("div.datagrid .datagrid-view1 div.datagrid-body-inner").height();
			var _d=$.data(jq[0],"datagrid").panel;
			var _10=_d.children("div.datagrid-view");
			var _11=_10.children("div.datagrid-view1");
			var _12=_10.children("div.datagrid-view2");
			var _13=_11.children("div.datagrid-header");
			var _14=_12.children("div.datagrid-header");
			var _15=_13.find("table");
			var _16=_14.find("table");
			hh=Math.max(_15.height(),_16.height());
			if(emptyData == 0){
				alert(_14.height());
				//_14.height(_14.height()+18);
				var datagrid_header_height = _14.height();
				$("div.datagrid .datagrid-view2 div.datagrid-header").height(120);
				$("div.datagrid .datagrid-view2 div.datagrid-header div.datagrid-header-inner").width(400);
			}*/
			//$(jq[0]).datagrid("_emptyContent",jq);
	     },
	     //datagrid表格最后一列宽度适应屏幕宽度
	     columnsWidth:function(jq){
	    	var datagridWidth = $(".datagrid").width();
			jq.each(function(){
				var opts=$.data(jq[0],"datagrid").options;
				if(opts.columns){
					var currentTable=$(jq[0]).datagrid("getPanel");
					var tableWidth = 0;
					if($("div.datagrid-view1") != null){
						tableWidth = tableWidth + currentTable.find("div.datagrid-view1 div.datagrid-header table").width();
					}
					if($("div.datagrid-view2") != null){
						tableWidth = tableWidth + currentTable.find("div.datagrid-view2 div.datagrid-header table").width();
						
					}
					//var cols = opts.columns[0];
					var colIndex =0;
					var colNumber =0;
					var rowNumber=1;
					for(var index=0; index < opts.columns.length;index++){
						if(opts.columns[index].length > colNumber && opts.columns[index][opts.columns[index].length -1].colspan ==1
								&& opts.columns[index][opts.columns[index].length -1].rowspan>=rowNumber){
							//colNumber = opts.columns[index].length ;
							//找到需要拉伸的列id
							colIndex = index;
							rowNumber=opts.columns[index][opts.columns[index].length -1].rowspan;
						}
					}
					var cols = opts.columns[colIndex];
					var col=cols[cols.length-1];
					var currentColWidth = col.width;
					//if(datagridWidth == tableWidth){alert("009999");return;}
					currentTable.find("div.datagrid-view2 div.datagrid-header tr td[field='"+col.field+"']").each(function(){
						//这个值不是正好的值，大于最适合的值
						//$(this).width(datagridWidth-currentColWidth);
					});
					
					currentTable.find("div.datagrid-view2 div.datagrid-header div.datagrid-header-inner").width(currentTable.find("div.datagrid-view2 div.datagrid-header").width());
					
					currentTable.find("div.datagrid-view2 div.datagrid-body tr td[field='"+col.field+"']").each(function(){
						$(this).width(datagridWidth-currentColWidth);
					});

					
				}
			})
			
	     },
	     emptyData:function(jq){
	    	 var emptyData = $("div.datagrid .datagrid-view1 div.datagrid-body-inner").height();
				var _d=$.data(jq[0],"datagrid").panel;
				var _10=_d.children("div.datagrid-view");
				var _11=_10.children("div.datagrid-view1");
				var _12=_10.children("div.datagrid-view2");
				var _13=_11.children("div.datagrid-header");
				var _14=_12.children("div.datagrid-header");
				var _15=_13.find("table");
				var _16=_14.find("table");
				hh=Math.max(_15.height(),_16.height());
				if(emptyData == 0){
					_14.height(hh-(_14.outerHeight()-_14.height())+18);
					$("div.datagrid .datagrid-view2 div.datagrid-header div.datagrid-header-inner").css("overflow-x","auto");
					//$("div.datagrid .datagrid-view2 div.datagrid-header div.datagrid-header-inner").css("overflow-y","hidden");
				}
				//alert("2222");
	     },
	     //steven 当列表为空时，标题显示不全的问题。
	     _emptyContent:function(jq)
	     {
	    	 var currentTable=$(jq[0]).datagrid("getPanel");
	    	 if(currentTable.find("div.datagrid-view2 div.datagrid-body table tbody").html() == ""){
				currentTable.find("div.datagrid-view2 div.datagrid-header").css("overflow-x","scroll");
				//currentTable.find("div.datagrid-view2 div.datagrid-header").height(getWinSize.winHeight()-71);
				currentTable.find("div.datagrid-view2 div.datagrid-header").height(40);
			 } 
	     },
	     
	     runresizeForTreeGrid:function(jq,obj)
		    {	
	    	 /*
				*o:要适应变换的面板
				*w:所在窗口对象
				*rh:要去除的高度(元素下方距离容器边缘的高度)
				*/
				var container = $(jq[0]).parent().parent().parent();		
				var containerDiv = $(jq[0]).parent().parent().parent().parent();
		        var containertop= container.offset().top;
				var theight;
				
				if(obj != null && obj.rh != null){
					theight = getWinSize.winHeight()-containertop-3-obj.rh;
				}else{
					theight = getWinSize.winHeight()-containertop-3;
				}
				if($(jq[0]).height != theight|| $(jq[0]).width !=twidth)
				   {      
					/*
					*249:左边west宽度
					*9:resizebar打开时宽度
					*6:resizebar关闭时宽度
					*20:当前表格所在区域两边padding
					*面板缩放或者窗口缩放
					*/
					//ie does not support css("padding")
					/*
					*17:DIV滚动条宽度
					*/
					//判断DiV是否出现滚动条
					var divScrollWidth = 0;
					//alert($(containerDiv)[0].scrollHeight+"**"+$(containerDiv)[0].clientHeight+"**"+$(containerDiv)[0].offsetHeight+"**"+$(containerDiv)[0].clientHeight);
					if($(containerDiv)[0].scrollHeight>$(containerDiv)[0].clientHeight||$(containerDiv)[0].offsetHeight>$(containerDiv)[0].clientHeight){
						divScrollWidth = 17;
					}
					
					twidth = getWinSize.winWidth()-3-container.offset().left-divScrollWidth; 
					
					/*设置datagrid遮罩层宽高*/
					$(".datagrid-mask").width(twidth);
					$(".datagrid-mask").height(theight);
				
					$(jq[0]).treegrid('resize', {
						width:twidth,
						height:theight
					});
		 
			   }
	     },
		
		
		
			// 显示蒙板
		    loading : function(jq) {
	    	 	var loading = $(jq[0]).data("loading");
	    	 	if(loading) {
	    	 		return false;
	    	 	} else {
	    	 		$(jq[0]).data("loading",true);
	    	 	}
				return jq.each(function() {
							$(this).datagrid("getPager")
									.pagination("loading");
							var opts = $(this).datagrid("options");
							if($.browser.msie&&($.browser.version == "6.0")){
								var wrap = $.data(this, "datagrid").panel;
								if (opts.loadMsg) {
									$("<div class=\"datagrid-mask\"></div>")
										.css( {
											display : "block",
											width : wrap.width(),
											height : wrap.height()
										}).appendTo(wrap);
									$("<div class=\"datagrid-mask-msg\"></div>")
											.html(opts.loadMsg)
											.appendTo(wrap)
											.css({
												display : "block",
												left : (wrap
														.width() - $(
														"div.datagrid-mask-msg",
														wrap)
														.outerWidth()) / 2,
												top : (wrap
														.height() - $(
														"div.datagrid-mask-msg",
														wrap)
														.outerHeight()) / 2
											});
								}
								
							}else if($.browser.msie && ($.browser.version > 6)){
								if (opts.loadMsg) {
									window.top.datagridMaskFun(opts.loadMsg);
								}
							}else{
								var wrap = $(window.parent.document.body);
								if (opts.loadMsg) {
									$("<div class=\"datagrid-mask\"></div>")
										.css( {
											display : "block",
											width : wrap.width(),
											height : wrap.height(),
											position:"absolute",
											left:"0px",
											top:"0px",
											zIndex:"1000",
											background: "#ccc",
											opacity:"0.3",
											filter:"alpha(opacity=30)"
										}).appendTo($(window.parent.document.body));
									$("<div class=\"datagrid-mask-msg\"></div>")
											.html(opts.loadMsg)
											.appendTo($(window.parent.document.body))
											.css({
												display : "block",
												left : window.document.body.clientWidth/2,
												top : window.document.body.clientHeight/2,
												position:"absolute",
												zIndex:"10000",
												cursor1:"wait",
												background:"#fff url('theme/default/css/easyui/default/images/pagination_loading.gif') no-repeat scroll 5px 10px",
												border:"2px solid #6593CF",
												color:"#222",
												width:"auto",
												height:"16px",
												padding:"12px 5px 10px 30px"
											});
								}
								
							}
							
							
							
						});
			 },
			// 隐藏蒙板
			loaded : function(jq) {
				$(jq[0]).data("loading",false); 
				if($.data(jq[0],"datagrid").options.loadSuccess) {
					$.data(jq[0],"datagrid").options.loadSuccess();
				}
				/*steven 处理没有列表数据时，显示一条空数据行，隐藏掉一些列表行符号，如复选框，序号等。
				 * 
				 * start
				 */
				$(jq[0]).datagrid("emptyDataHandle",jq);
				/*
				 * end
				 */
				return jq.each(function() {
					var _this=this;
					$(this).datagrid("getPager").pagination(
							"loaded");
					var wrap;
					if($.browser.msie&&($.browser.version == "6.0")){
						wrap = $.data(this, "datagrid").panel;
					}else if($.browser.msie && ($.browser.version > 6)){
						wrap = $(window.top.document.body);
					}else{
						wrap = $(window.parent.document.body);
					}
					wrap.find("div.datagrid-mask-msg").remove();
					wrap.find("div.datagrid-mask").remove();
				});
			},
			//steven 处理没有列表数据时，显示一条空数据行，隐藏掉一些列表行符号，如复选框，序号等。
			emptyDataHandle:function(jq){
				var _a6=$.data(jq[0],"datagrid").panel;
				var totalData=$.data(jq[0],"datagrid").data;
				var _3e=$.data(jq[0],"datagrid").options;
				_a6.find("td[field=ck] div.datagrid-header-check","div.datagrid-view1 div.datagrid-header").find("[type=checkbox]").css("visibility","visible");
				if(totalData != undefined){
					if(totalData.total == 0){
						//_a6.find("td[field=ck] div.datagrid-cell-check","div.datagrid-view1 div.datagrid-body").html("");
						_a6.find("td[field=ck] div.datagrid-cell-check","div.datagrid-view1 div.datagrid-body").find("[type=checkbox]").css("visibility","hidden");
						//_a6.find("td[field=ck] div.datagrid-header-check","div.datagrid-view1 div.datagrid-header").html("");
						_a6.find("td[field=ck] div.datagrid-header-check","div.datagrid-view1 div.datagrid-header").find("[type=checkbox]").css("visibility","hidden");
						_a6.find("div.datagrid-view1 div.datagrid-body td[field=indexer] div.datagrid-cell").html("");
						_a6.find(".datagrid-body td").css({"border-right-color":"#EDFBFE","border-bottom-color":"#EDFBFE"});
						_a6.find(".datagrid-row-alt-empty div.datagrid-cell").css("background","#EDFBFE");
						_a6.find(".datagrid-row-alt-empty").css("background","#EDFBFE");		
					}
				}
			},
			loadSuccess : function() {
				
			},
			_initRowOptButtons:function(jq){
				return jq.each(function() {
					var _this=this;
					var operations=$(this).datagrid("_getRowOperations");
					var panel = $.data(this, "datagrid").panel;

					
					var rows=$(this).datagrid("getRows");
					$.each(rows,function(rowIndex,o){
						$.each(operations,function(optIndex,str){
							
							var buttons=panel.find("a.dg-operation-button-"+str.name+"Row-"+rowIndex);
							if(str.name=="cancel"||str.name=="save"){
								$(buttons[0]).hide();
							}else{
								$(buttons[0]).show();
							}
							$(buttons[0]).unbind();
							$(buttons[0]).bind("click",function(){
								$(_this).datagrid("_m_"+str.name+"Row",rowIndex);
								return false;
							});
						})
						
						
					})
				});
			},
			_getRowOperations:function(jq){
				var opts=$.data(jq[0],"datagrid").options;
				if(opts.columns){
					for(var i=0;i<opts.columns.length;i++){
						var cols=opts.columns[i];
						for(var j=0;j<cols.length;j++){
							var col=cols[j];
							if(col.operations){
								return col.operations;
								
							}
						}
					}
				}
				return [];
			},
			_m_editRow : function(jq, index) {
				jq.each(function() {
							var gData = $(this).datagrid("getData");
							var options=$.data(jq[0],"datagrid").options;
							var gRows = gData.rows;
							if (options.pageEdit) {
								$(this).datagrid("beginEdit",index);
							} else {
								var url = options.operations.edit.url;
								if(url.indexOf('?') >0){
									url+="&";
								}
								else{
									url+="?";
								}
								
								
								
								if (options.operations.edit.paramNames
										&& options.operations.edit.paramNames) {
									for ( var i = 0; i < options.operations.edit.paramNames.length; i++) {
		
										url = url
												+ options.operations.edit.paramNames[i]
												+ "="
												+ eval('gRows[index].' + options.operations.edit.paramValues[i])
												+ "&";
									}
								}
								if (options.operations.edit.isKeep) {
									//url = url + "params.sessionKeep=true";
								}
								document.location.href = url;
							}
						});
				
	
			},
			_m_enableRow : function(jq, index) {
				jq.each(function() {
					var gData = $(this).datagrid("getData");
					var options=$.data(jq[0],"datagrid").options;
					var gRows = gData.rows;
					var url = options.operations.enable.url;
					if(url.indexOf('?') >0){
						url+="&";
					}
					else{
						url+="?";
					}
					
					
					
					if (options.operations.enable.paramNames && options.operations.enable.paramNames) {
						for ( var i = 0; i < options.operations.enable.paramNames.length; i++) {
							url = url + options.operations.enable.paramNames[i]
									+ "="
									+ eval('gRows[index].' + options.operations.enable.paramValues[i])
									+ "&";
						}
					}
					
					$.post(url, {}, function(response){
						if (response.status == '0') {
							$(jq[0]).datagrid('reload');
						}
					}, 'json');
				});
			},
			_m_disableRow : function(jq, index) {
				jq.each(function() {
					var gData = $(this).datagrid("getData");
					var options=$.data(jq[0],"datagrid").options;
					var gRows = gData.rows;
					var url = options.operations.disable.url;
					if(url.indexOf('?') >0){
						url+="&";
					}
					else{
						url+="?";
					}
					
					
					if (options.operations.disable.paramNames && options.operations.disable.paramNames) {
						for ( var i = 0; i < options.operations.disable.paramNames.length; i++) {
							url = url + options.operations.disable.paramNames[i]
									+ "="
									+ eval('gRows[index].' + options.operations.disable.paramValues[i])
									+ "&";
						}
					}
					
					$.post(url, {}, function(response){
						if (response.status == '0') {
							$(jq[0]).datagrid('reload');
						}
					}, 'json');
				});
			},
			// 保存编辑方法 for api
			_m_saveRow : function(jq, index) {
				$(jq[0]).datagrid('endEdit',index);
				var gData = $(jq[0]).datagrid("getData");
				var operations=$.data(jq[0],'datagrid').options.operations;
				var gRows = gData.rows;
				var idField =$.data(jq[0],"datagrid").options.idField;
		
				if (eval('gRows[index].' + idField) == undefined)  {
					$(jq[0]).datagrid('save', [index,operations.update]);
				} else {
					$(jq[0]).datagrid('save', [index,operations.save]);
				}
			},
			getEditingRowIndex:function(jq){
				var rows = $(jq[0]).datagrid("getData").rows;
				var index=null;
				$.each(rows,function(i,o){
					if(o.editing)
						index=i;
				})
				return index;
			},
			_initAddRow : function(jq) {
					var options=	$.data(jq[0],'datagrid').options;
					var row = new Array();
					if (options.forzenColumns) {
						for ( var i = 0; i < options.forzenColumns.length; i++) {
							for ( var j = 0; j < options.forzenColumns[i].length; j++) {
								var fCol = options.forzenColumns[i][j];
								row[fCol.field] = fCol.defaultValue;
							}
						}
					}
					if (options.columns) {
						for ( var i = 0; i < options.columns.length; i++) {
							for ( var j = 0; j < options.columns[i].length; j++) {
								var col = options.columns[i][j];
								if (col.edittemplate)
									continue;
								row[col.field] = col.defaultValue;
							}
						}
					}
					return row;

				
			},
			// 取消的出口方法 for api
			_m_cancelRow : function(jq,index) {
				var gData = $(jq[0]).datagrid("getData");
				var gRows = gData.rows;
				var idflag =$.data(jq[0],"datagrid").options.idField;
				if (eval('gRows[index].' + idflag) == undefined) {
					$(jq[0]).datagrid('deleteRow', index);
				} else {
					$(jq[0]).datagrid('cancelEdit', index);
				}
			},
			// 添加的出口方法
			addRecord : function(jq) {
				if($(jq[0]).datagrid("getEditingRowIndex")==null)
				return jq.each(function() {
					options=$.data(this,"datagrid").options;
					if (options.pageEdit) {
						var row =$(this).datagrid('_initAddRow');
						$(this).datagrid('addRow',row);
					} else {
						var url =options.operations.add.url;
						document.location.href = url;
					}
				});
				
			},
			removeRow:function(jq,rowindex){
				return jq.each(function(){
					$(jq[0]).datagrid("_m_removeRow",rowindex);
				});
			}
			,
			
			hideColumn:function(jq){
				jq.each(function(){
					//var rows=$(this).datagrid("getRows");
					//$.each(rows,function(rowIndex,o){
					var opts=$.data(jq[0],"datagrid").options;
					if(opts.columns){
						for(var i=0;i<opts.columns.length;i++){
							var cols=opts.columns[i];
							for(var j=0;j<cols.length;j++){
								var col=cols[j];
								if(col.isOperation){
									var currentTable=$(jq[0]).datagrid("getPanel");
									//alert(rows[rowIndex][[col.field]]);
									/*currentTable.find("div.datagrid-view2 div.datagrid-body tr td[field="+col.field+"] div.datagrid-cell").each(function(){
										if($(this).html() == ""){
											currentTable.find("td[field="+col.field+"]").hide();
										}
									});*/
									
									currentTable.find("div.datagrid-view2 div.datagrid-body tr td[field='"+col.field+"'] div.datagrid-cell").each(function(){
										if($(this).html() == ""){
											/*
											 *用这个循环增加运算开销 
											currentTable.find("td[field="+col.field+"]").hide();*/
											/*
											 * 分别隐藏数据表格的td和表头title部分的td
											 * */
											$(this).parent().hide();
											$(currentTable.find("div.datagrid-view2 div.datagrid-header tr td[field='"+col.field+"']")[0]).hide();
										}
									});
									
								}	
							}
						}
					}
					
				})
				
			},
			// 单行删除
			_m_removeRow : function(jq,rowindex) {
				return jq.each(function(){
					var gData = $(this).datagrid("getData");
					var gRows = gData.rows;
					var operations=$.data(this,'datagrid').options.operations;
					for ( var i = 0; i < gRows.length; i++) {
						if (i == rowindex) {
							var select = gRows[i];
							jConfirm(operations.remove.confirm,'确认对话框',
							function(r) {
								if (r) {
									$.tdqsAjax( {
											type : "post",
											url : operations.remove.url,// 目标地址
											data : operations.remove.paramNames[0]
													+ "="
													+ eval('select.' +operations.remove.paramValues[0]),
											beforeSend : function() {
												$(jq[0]).datagrid("loading");
											},
											complete : function() {

											},
											error : function() {

											},
											success : function(
													json) {
												var r =eval(json);
												if(r.status ==TDQS.AJAX_STATUS_SUCCESS)
												{
													showMessage(operations.remove.success);
												} else {
													showMessage(r.message);
												}
													$(jq[0]).datagrid('reload');
												
											}
										});
									} else {
											$(jq[0]).datagrid('unselectRow',rowindex);
										}
									});
							$(".messager-body").parent().bgiframe();
						}
					}
				});
				

			},
			// 批量删除
			batchDelete : function(jq) {
				var select = $(jq[0]).datagrid('getSelections');
				var operations=$.data(jq[0],'datagrid').options.operations;
					if (select && select != "") {
						var primaryValue = "";
						for ( var i = 0; i < select.length; i++) {
							if (i < select.length - 1) {
								primaryValue += eval('select[i].' +operations.batchRemove.paramValues[0])+ ",";
										
							} else {
								primaryValue += eval('select[i].' + operations.batchRemove.paramValues[0]);
							}
						}
						
								jConfirm(operations.batchRemove.confirm,'确认对话框',
										function(r) {
											if (r) {
											$.tdqsAjax( {
												type : "post",
												url : operations.batchRemove.url,// 目标地址
												data : {id:primaryValue},
												beforeSend : function() {
													$(jq[0]).datagrid("loading");
												},
												complete : function() {

												},
												error : function() {

												},
												success : function(
														result) {													
													 var json = result; 
											         if(json.status==TDQS.AJAX_STATUS_SUCCESS) {
														showMessage(operations.batchRemove.success);
														$(jq[0]).datagrid("loaded");
														$(jq[0]).datagrid('reload');
														$(jq[0]).datagrid('clearSelections');
													} else {
														showMessage(result.message);
														$(jq[0]).datagrid("loaded");
														$(jq[0]).datagrid('clearSelections');
													}
											        
												}
													});
										} else {
											return;
										}
								});
								$(".messager-body").parent().bgiframe();

							} else {
								showMessage(operations.batchRemove.select);
							}
				},
				// 添加行
				addRow:function(jq,row) {
					return jq.each(function(){
						var view=$.data(this,"datagrid").options.view;
						view.insertRow.call(view,this,0,row);
						///$(this).datagrid('appendRow',row);
						$(this).datagrid("_initRowOptButtons");
						$(this).datagrid('beginEdit', 0);
						
					});
				},
				// 保存
				 save:function(jq, options) {
					var index=options[0];
					var oper=options[1];
					var gData = $(jq[0]).datagrid("getData");
					var gRows = gData.rows;
					for ( var i = 0; i < gRows.length; i++) {
						if (i == index) {
							jConfirm( oper.confirm,'确认对话框', function(r){
								if (r){
									$.tdqsAjax( {
										type : "POST",
										url : oper.url,
										data : getParams(oper, gRows[index]),
										beforeSend : function() {
										$(jq[0]).datagrid("loading");
										},
										complete : function() {

										},
										error : function() {

										},
										success : function(json) {
												showMessage(oper.success);
												$(jq[0]).datagrid("loaded");
												$(jq[0]).datagrid('reload');
											
										}
									});
								}else{
									$(jq[0]).datagrid("beginEdit", index);
								}
							});
							$(".messager-body").parent().bgiframe();
						}
					}
				},
				refreshButtons:function(jq,index){
					var panel = $.data(jq[0], "datagrid").panel;
					var buttons=panel.find("a.dg-operation-button-cancelRow-"+index);
					$(buttons[0]).toggle();
					buttons=panel.find("a.dg-operation-button-saveRow-"+index);
					$(buttons[0]).toggle();
					buttons=panel.find("a.dg-operation-button-removeRow-"+index);
					$(buttons[0]).toggle();
					buttons=panel.find("a.dg-operation-button-editRow-"+index);
					$(buttons[0]).toggle();
				}
			});
	
	$.extend($.fn.datagrid.defaults, {
		width : window.innerWidth - 200,
		height : 350,
		nowrap : false,
		singleSelect : false,
		rowStyler : function(index, row, css) {
	
				if (index % 2 != 0) {
					return "";
				}
			
		},
		pageEdit:false,
		rowCss : "",
		striped : true,
		pageNumber : 1,
		pageSize : 10,
		onHeaderContextMenu : function(e, field) {
			e.preventDefault();
			if (!$('#tmenu').length) {
				var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo(
				'body');
				var fields = $('#' + datagrid.grid.tableId).datagrid('getColumnFields');
				for ( var i = 0; i < fields.length; i++) {
					var menutitle = fields[i];
					for ( var j = 0; j < datagrid.grid.columns.length; j++) {
						for ( var z = 0; z < datagrid.grid.columns[j].length; z++) {
							if (datagrid.grid.columns[j][z].field == fields[i]) {
								menutitle = datagrid.grid.columns[j][z].title;
							}
						}
						$('<div id=' + fields[i] + ' iconCls="icon-select"/>').html(menutitle).appendTo(tmenu);
					}

				tmenu.menu( {
					onClick : function(item) {
						if (item.iconCls == 'icon-select') {
							$('#' + datagrid.grid.tableId).datagrid('hideColumn',
							$(item).attr('id'));
							tmenu.menu('setIcon', {
								target : item.target,
								iconCls : 'icon-unselect'
							});
					} else {
						$('#' + datagrid.grid.tableId).datagrid('showColumn',$(item).attr('id'));
						tmenu.menu('setIcon', {
							target : item.target,
							iconCls : 'icon-select'
						});
					}
				}
				});
				}
				$('#tmenu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
			},
		pagination : true,
		onBeforeEdit : function(index, row) {
			row.editing = true;
			//$(this).datagrid('refreshRow', index);
			$(this).datagrid('refreshButtons', index);

		},
		onAfterEdit : function(index, row) {
			row.editing = true;
			//$(this).datagrid('refreshRow', index);
			$(this).datagrid('refreshButtons', index);
		},
		onCancelEdit : function(index, row) {
			row.editing = false;
			//$(this).datagrid('refreshRow', index);
			$(this).datagrid('refreshButtons', index);
		},
		operationFormtter : function(value, row, index) {
			var opers = '';
			
			if (!this.operations) {
				return;
			}
			
			for (var i=0; i<this.operations.length; i++){
				
				var oper = this.operations[i];
				
				if (oper.display == undefined || oper.display(value, row, index)){
					opers += '<a href="javascript:void(0)" class="commonOper  dg-operation-button-'+oper.name+'Row-'+index+'" >[' 
					+ oper.text + ']</a>&nbsp;';
				}
			}
			return opers;
		},
		indexFormatter:function(value,row, index) {
	 		if(row.length==0){
	 			return 0;
	 		}else{
	 			return index+1;
			}
		},
		childFormatter:function(value,row, index,name) {
	 		// 因为参数中的name为空，没有属性名称， 字方法暂时不能用。
			var obj = row;
			var pas = name.split('.');		
			for(var _0i=0;_0i<pas.length;_0i++)
			{				
				var name = pas[_0i].toString();
				obj = obj[name];
				
			}	
			return obj;
			
		}				
						
						
						
	})
	function getParams(oper, row) {
		var params = "";
		if (oper.paramNames && oper.paramValues) {
			for ( var i = 0; i < oper.paramNames.length; i++) {
				params += oper.paramNames[i] + "=" + row[oper.paramValues[i]] + "&";
			}
		}
		return params;
	}
})(jQuery);

function showMessage(msg) {
	jAlert(msg);
}
function getFormParams(formId){
	var queryParams = {};
	$('input,select,textarea',document.getElementById(formId)).each(function(){
		if($(this).attr('name') && (!this.disabled || this.disabled=="")) {
			if(queryParams[$(this).attr('name')]) {
				if(queryParams[$(this).attr('name')+"_length"]) {
					queryParams[$(this).attr('name')+"["+queryParams[$(this).attr('name')+"_length"]+"]"] = $(this).val();
					queryParams[$(this).attr('name')+"_length"] = new Number(queryParams[$(this).attr('name')+"_length"])+1;
				}
				else {
					var value = queryParams[$(this).attr('name')];
					queryParams[$(this).attr('name')+"[0]"] = value;
					queryParams[$(this).attr('name')+"[1]"] = $(this).val();
					queryParams[$(this).attr('name')+"_length"] = 2;
				}
			}
			else {
				queryParams[$(this).attr('name')]=$(this).val();
			}
		}
	});
	return queryParams;
}
